package com.wymobilearchitecture.demo.banner

import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.wy.w_ui.LoadImageUtil

import com.wy.w_ui.banner.WBanner
import com.wy.w_ui.banner.core.WBannerBean
import com.wymobilearchitecture.R
/**
 * kotlinx.android.synthetic
 */
import kotlinx.android.synthetic.main.activity_banner.*


class BannerActivity : AppCompatActivity(){

    private val images = arrayOf<String>("https://img1.baidu.com/it/u=394698104,1302019637&fm=26&fmt=auto&gp=0.jpg",
        "https://img2.baidu.com/it/u=794857819,2982730120&fm=26&fmt=auto&gp=0.jpg",
        "https://img2.baidu.com/it/u=3791123780,4261799713&fm=26&fmt=auto&gp=0.jpg")

     private lateinit var banner : WBanner

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_banner)

        initView(true)



        btn_start.setOnClickListener {
            initView(true)
        }

        btn_end.setOnClickListener{
          initView(false)
        }
    }

    fun initView(autoPlay: Boolean){
        banner = findViewById(R.id.banner)
        val bannerData : MutableList<WBannerBean> = ArrayList()
        for (i in images.indices){
            val mo : WBannerBean = BannerBean()
            mo.url = images[i % images.size]
            bannerData.add(mo)
        }

        banner.setAutoPlay(autoPlay)
        banner.setIntervalTime(2000)

        banner.setBannerData(R.layout.banner_item,bannerData)
        banner.setBindAdapter{viewHolder, bean, position ->
            val imageView :ImageView = viewHolder.findViewById(R.id.iv_image)

            LoadImageUtil.load(this,bean.url,imageView)
            val title : TextView = viewHolder.findViewById(R.id.tv_title)
            title.text = bean.url
        }


    }

}